package com.lin.mr.maizilaundry.myadapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.android.smartimage.SmartImageView;
import com.lin.mr.maizilaundry.R;
import com.lin.mr.maizilaundry.entity.ClothInfo;

import java.util.List;

/**
 * Created by lenovog on 2016/8/8.
 */
public class GridViewAdapter extends BaseAdapter {
    Context context;
    List<ClothInfo> clothInfoList;

    public GridViewAdapter( Context context,List<ClothInfo> clothInfoList) {
        this.clothInfoList = clothInfoList;
        this.context = context;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ClothInfo clothInfo = clothInfoList.get(position);
        ViewHolder vh = null;
        if (convertView == null){
            LayoutInflater inflater = LayoutInflater.from(context);
            convertView = inflater.inflate(R.layout.fragment_cloth_item,null);
            vh = new ViewHolder();
            vh.iv_image_cloth = (SmartImageView) convertView.findViewById(R.id.iv_image_cloth);
            vh.tv_cloth_name = (TextView) convertView.findViewById(R.id.tv_cloth_name);
            vh.tv_cloth_price = (TextView) convertView.findViewById(R.id.tv_cloth_price);
            convertView.setTag(vh);
        }else {
            vh = (ViewHolder) convertView.getTag();
        }
        vh.iv_image_cloth.setImageUrl(clothInfo.getWashHead());
        vh.tv_cloth_name.setText(clothInfo.getWashName());
        vh.tv_cloth_price.setText(clothInfo.getAmount());
        return convertView;
    }

    class ViewHolder{
        SmartImageView iv_image_cloth;
        TextView tv_cloth_name,tv_cloth_price;
    }

    @Override
    public int getCount() {
        return clothInfoList.size();
    }

    @Override
    public Object getItem(int position) {
        return position;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }


}
